Fitting PD-NEUT-TOF NCAF-WISH¶
This example shows how to refine the crystal structure parameters of Si from neutron diffraction data in a time-of-flight experiment performed on SEPD diffractometer at Argonne.
Import¶
import easydiffraction as ed
Job¶
Create a job — the main object to store all the information
job = ed.Job(type='tof')
Model¶
Load a phase from CIF file
job.add_phase_from_file('data/ncaf.cif')
print(job.phases)
Collection of 1 phases: ['ncaf']
Show phase info in CIF format
phase = job.phases['ncaf']
print(phase.cif)
data_ncaf _cell_length_a 10.250256 _cell_length_b 10.250256 _cell_length_c 10.250256 _cell_angle_alpha 90.00000000 _cell_angle_beta 90.00000000 _cell_angle_gamma 90.00000000 _space_group_name_H-M_ref 'I 21 3' loop_ _atom_site_label _atom_site_type_symbol _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy _atom_site_adp_type _atom_site_B_iso_or_equiv Ca Ca 0.4661 0.00000000 0.25 1.00000000 Biso 0.9 Al Al 0.25171 0.25171 0.25171 1.00000000 Biso 0.66 Na Na 0.08481 0.08481 0.08481 1.00000000 Biso 1.9 F1 F 0.1375 0.3053 0.1195 1.00000000 Biso 0.9 F2 F 0.3626 0.3634 0.1867 1.00000000 Biso 1.28 F3 F 0.4612 0.4612 0.4612 1.00000000 Biso 0.79
Display the crystal structure of a given model
job.show_crystal_structure(id='ncaf')
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol
Experiment¶
Load experimentally measured data from a file in XYE format
job.add_experiment_from_file('data/wish.xye')
Display the experimentally measured data
job.show_experiment_chart()
Define a point background
background_points = [
( 9162, 465),
( 11136, 593),
( 13313, 497),
( 14906, 546),
( 16454, 533),
( 17352, 496),
( 18743, 428),
( 20179, 452),
( 21368, 397),
( 22176, 468),
( 22827, 477),
( 24644, 380),
( 26439, 381),
( 28257, 378),
( 31196, 343),
( 34034, 328),
( 37265, 310),
( 41214, 323),
( 44827, 283),
( 49830, 273),
( 52905, 257),
( 58204, 260),
( 62916, 261),
( 70186, 262),
( 74204, 262),
( 82103, 268),
( 91958, 268),
(102712, 262)
]
job.set_background(background_points)
Display the experiment chart after setting the background
job.show_experiment_chart()
Analysis¶
Display the analysis chart before setting initial parameter values
job.show_analysis_chart()
Create aliases for the two types of experimental parameters
pattern_params = job.pattern
experiment_params = job.parameters
Change the default value of some instrumental parameters and display the analysis chart again
experiment_params.dtt1 = 20770
experiment_params.dtt2 = -1.08308
experiment_params.ttheta_bank = 152.827
job.show_analysis_chart()
Change the scale and display the analysis chart again
phase.scale = 0.5
job.show_analysis_chart()
Change the default values of the peak profile related parameters and display the analysis chart again
experiment_params.alpha0 = 0
experiment_params.alpha1 = 0.1
experiment_params.beta0 = 0.01
experiment_params.beta1 = 0.01
experiment_params.sigma0 = 0
experiment_params.sigma1 = 0
experiment_params.sigma2 = 5
job.show_analysis_chart()
Select parameters to be refined in the first round
phase.scale.free = True
pattern_params.zero_shift.free = True
Print parameters to be refined (free parameters) before fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | scale | 0.5 | 0.0 |
Start Least-Squares minimization to refine the selected parameters
job.fit()
Fitting successful Duration: 11.75 s Reduced chi: 19.03
Print the refined parameters after fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | scale | 0.983169 | 0.005159 | |
| 2 | zero_shift | -3.376425 | 0.085604 | µs |
Display the analysis chart after the first fitting
job.show_analysis_chart()
Select more parameters to be refined in the second round
experiment_params.alpha1.free = True
experiment_params.beta0.free = True
experiment_params.beta1.free = True
experiment_params.sigma2.free = True
Print free parameters before the second fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | scale | 0.983169 | 0.005159 | |
| 2 | sigma2 | 5.000000 | 0.000000 | |
| 3 | alpha1 | 0.100000 | 0.000000 | |
| 4 | beta0 | 0.010000 | 0.000000 | |
| 5 | beta1 | 0.010000 | 0.000000 | |
| 6 | zero_shift | -3.376425 | 0.085604 | µs |
Start the second round of minimization
job.fit()
Fitting successful Duration: 25.71 s Reduced chi: 6.87
Print free parameters after the third fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | scale | 1.085347 | 0.003434 | |
| 2 | sigma2 | 13.778083 | 0.764276 | |
| 3 | alpha1 | 0.083958 | 0.001075 | |
| 4 | beta0 | 0.006515 | 0.000041 | |
| 5 | beta1 | 0.012430 | 0.000216 | |
| 6 | zero_shift | -3.440901 | 0.076697 | µs |
Display the analysis chart after the third fitting
job.show_analysis_chart()